#!/bin/sh

cmd=$1
if test "$1" = "prompt"; then
  cmd=`printf "connect\ndisconnect" | dmenu`
fi

case $cmd in
  "connect")
    bluetoothctl power on
    devices=`bluetoothctl devices | cut -d' ' -f2-`
    chosen=`echo "$devices" | dmenu`
    if test "$chosen" != ""; then
      address=`echo "$chosen" | cut -d' ' -f1`
      output=`bluetoothctl connect "$address"`
      notify-send "$output"
    fi
    ;;
  "disconnect")
    devices=`bluetoothctl devices | cut -d' ' -f2-`
    chosen=`echo "$devices" | dmenu`
    if test "$chosen" != ""; then
      address=`echo "$chosen" | cut -d' ' -f1`
      output=`bluetoothctl disconnect "$address"`
      notify-send "$output"
    fi
    ;;
  *)
    ;;
esac
